package com.example.inspurfabricapp.exception;

import com.example.inspurfabricapp.common.Result;
import org.hyperledger.fabric.gateway.ContractException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理程序
 *
 * @author lijiahao
 * @date 2024/06/26
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 合约错误
     *
     * @param ce 合约错误
     * @return Result
     * @author lijiahao
     * @date 2024/06/26
     */
    @ExceptionHandler(ContractException.class)
    @ResponseBody
    public Result handle(ContractException ce) {
        return Result.fail(ce.getMessage());
    }
}
